package com.zhugang.week04;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @program algorithms
 * @description: canAttendMeetings
 * @author: chanzhugang
 * @create: 2022/07/02 17:03
 */
public class CanAttendMeetings {

    public static void main(String[] args) {
        CanAttendMeetings canAttendMeetings = new CanAttendMeetings();
        int[][] intervals = {{0, 4}, {5, 10}, {9, 20}};
        boolean flag = canAttendMeetings.canAttendMeetings(intervals);
        System.out.println(flag);
    }

    /**
     * 252 会议室
     *
     * @param intervals
     * @return
     */
    public boolean canAttendMeetings(int[][] intervals) {
        // 先排序，再比较后一个数组第一个值和前一个数组第二个值大小
        Arrays.sort(intervals, Comparator.comparingInt(o -> o[0]));
        for (int i = 1; i < intervals.length; i++) {
            if (intervals[i][0] < intervals[i - 1][1]) {
                return false;
            }
        }
        return true;
    }
}